# !/usr/bin/env python
# -*- coding: utf-8 -*-
# @File  : 结构化数据-JSON Schema.py
# @Author: dongguangwen
# @Date  : 2025-03-23 20:49
from langchain_openai import ChatOpenAI


model = ChatOpenAI(model="Pro-128K", api_key="dzCDkUHufCZEsuWlfVQd:",
                   base_url="https://spark-api-open.xf-yun.com/v1")


json_schema = {
    "title": "joke",
    "description": "Joke to tell user.",
    "type": "object",
    "properties": {
        "setup": {
            "type": "string",
            "description": "The setup of the joke",
        },
        "punchline": {
            "type": "string",
            "description": "The punchline to the joke",
        },
        "rating": {
            "type": "integer",
            "description": "How funny the joke is, from 1 to 10",
            "default": None,
        },
    },
    "required": ["setup", "punchline"],
}

structured_llm = model.with_structured_output(json_schema)

structured_llm.invoke("Tell me a joke about cats")
